var t = require("../../../component/WxNotificationCenter/WxNotificationCenter.js"), a = getApp();

Page({
    data: {
        avatar: "/images/avatar.png",
        name: "",
        job: 0,
        price: "",
        sex: 0,
        call: "",
        city: "",
        birthday: "",
        age: "",
        height: "",
        weight: "",
        sign: "",
        summary: "",
        roleNames: a.globalData.roleAllNames,
        sexs: [ "女", "男" ],
        heights: [],
        weights: [],
        needUpdate: !0
    },
    onLoad: function(t) {
        var a = t.avatar;
        console.log(a), a && (this.uploadAvatar(a), this.setData({
            src: a
        }));
        for (var e = [], i = [], o = 150; o < 200; o++) e = e.concat(o + "cm");
        for (o = 30; o < 100; o++) i = i.concat(o + "kg");
        this.setData({
            heights: e,
            weights: i
        });
    },
    getData: function() {
        var t = this;
        a.network.post({
            url: a.url.userInfo,
            params: {},
            before: function() {},
            success: function(e) {
                if (1 == e.data.result) {
                    e.data.data;
                    a.globalData.userInfo = e.data.data.info, wx.setStorageSync(a.storage.userInfo, e.data.data), 
                    t.updateData();
                }
            },
            fail: function() {
                a.util.showToast("获取失败，请重试");
            },
            complete: function() {}
        });
    },
    uploadAvatar: function(t) {
        var e = this;
        a.network.uploadFile({
            url: a.url.editInfoAvatar,
            filePath: t,
            name: "file",
            formData: {},
            before: function() {
                e.setData({
                    uploading: !0,
                    progress: 0
                }), wx.showLoading({
                    title: "提交数据"
                });
            },
            success: function(t) {
                wx.hideLoading(), a.util.showToast(t.message), 1 == t.result && e.getData();
            },
            fail: function() {
                wx.hideLoading(), a.util.showToast("提交数据失败");
            },
            complete: function() {
                e.setData({
                    uploading: !1,
                    progress: 0
                });
            }
        });
    },
    updateData: function() {
        var t = a.globalData.userInfo;
        if (null != t) {
            var e = t.prices ? t.prices : [], i = "";
            if (e.length > 0) {
                var o = e[0];
                i = o.area + " " + o.price + "元";
            }
            var n = t.province + " " + t.city + " " + t.county;
            this.setData({
                avatar: t.avatar,
                name: t.name,
                job: t.role,
                price: i,
                sex: t.sex,
                call: t.phone,
                city: n,
                birthday: t.birthday,
                age: t.age,
                height: t.height + "cm",
                weight: t.weight + "kg",
                sign: t.signature,
                summary: t.intro
            });
        }
    },
    clickAvatar: function(t) {
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var a = t.tempFilePaths[0];
                wx.redirectTo({
                    url: "upload/upload?src=" + a
                });
            }
        });
    },
    clickName: function(t) {
        wx.navigateTo({
            url: "editName/editName"
        });
    },
    clickPrice: function(t) {
        wx.navigateTo({
            url: "editPrice/editPrice"
        });
    },
    clickPhone: function(t) {
        wx.navigateTo({
            url: "editPhone/editPhone"
        });
    },
    changeRole: function(e) {
        var i = e.detail.value;
        if (this.data.job != i) {
            var o = this.data.roleNames[i];
            console.log("role:" + o);
            var n = this;
            wx.showModal({
                title: "提示",
                content: "职业仅能修改两次，确定要将职业修改为" + o + "?",
                success: function(e) {
                    e.confirm ? a.network.post({
                        url: a.url.changeRole,
                        params: {
                            role: i
                        },
                        before: function() {
                            wx.showLoading({
                                title: "正在修改"
                            });
                        },
                        success: function(e) {
                            if (wx.hideLoading(), a.util.showToast(e.data.message), 1 == e.data.result) {
                                n.getData();
                                var o = getCurrentPages();
                                o[o.length - 2].setData({
                                    needUpdate: !0
                                }), wx.setStorageSync(a.storage.role, i), t.postNotificationName("didLoginSuccess"), 
                                wx.navigateBack({});
                            }
                        },
                        fail: function() {
                            wx.hideLoading(), a.util.showToast("修改失败");
                        },
                        complete: function() {}
                    }) : e.cancel && console.log("用户点击取消");
                }
            });
        } else a.utils.showToast("与当前角色一致");
    },
    changeSex: function(t) {
        var e = t.detail.value, i = this;
        a.network.post({
            url: a.url.editInfo,
            params: {
                sex: e
            },
            before: function() {
                wx.showLoading({
                    title: "修改中"
                });
            },
            success: function(t) {
                wx.hideLoading(), a.util.showToast(t.data.message), 1 == t.data.result && (a.util.showToast("修改成功"), 
                i.getData());
            },
            fail: function() {
                wx.hideLoading(), a.util.showToast("修改失败，请重试");
            },
            complete: function() {}
        });
    },
    changeWeight: function(t) {
        var e = t.detail.value, i = parseInt(e) + 30, o = this;
        a.network.post({
            url: a.url.editInfo,
            params: {
                weight: i
            },
            before: function() {
                wx.showLoading({
                    title: "修改中"
                });
            },
            success: function(t) {
                wx.hideLoading(), a.util.showToast(t.data.message), 1 == t.data.result && o.getData();
            },
            fail: function() {
                wx.hideLoading(), a.util.showToast("修改失败，请重试");
            },
            complete: function() {}
        });
    },
    changeHeight: function(t) {
        var e = t.detail.value, i = parseInt(e) + 150, o = this;
        a.network.post({
            url: a.url.editInfo,
            params: {
                height: i
            },
            before: function() {
                wx.showLoading({
                    title: "修改中"
                });
            },
            success: function(t) {
                wx.hideLoading(), a.util.showToast(t.data.message), 1 == t.data.result && o.getData();
            },
            fail: function() {
                wx.hideLoading(), a.util.showToast("修改失败，请重试");
            },
            complete: function() {}
        });
    },
    clickSummary: function(t) {
        wx.navigateTo({
            url: "editSummary/editSummary"
        });
    },
    clickSign: function(t) {
        wx.navigateTo({
            url: "editSign/editSign"
        });
    },
    clickCity: function(t) {
        wx.navigateTo({
            url: "editCity/editCity"
        });
    },
    bindTimeChange: function(t) {
        console.log(t.detail.value);
        var e = this;
        a.network.post({
            url: a.url.editInfo,
            params: {
                birthday: t.detail.value
            },
            before: function() {
                wx.showLoading({
                    title: "修改中"
                });
            },
            success: function(t) {
                wx.hideLoading(), a.util.showToast(t.data.message), 1 == t.data.result && e.getData();
            },
            fail: function() {
                wx.hideLoading(), a.util.showToast("修改失败，请重试");
            },
            complete: function() {}
        });
    },
    onShow: function() {
        this.data.needUpdate && (this.getData(), this.updateData(), this.setData({
            needUpdate: !1
        }));
    },
    onShareAppMessage: function() {
        var t = a.util.getShareInfo();
        return {
            title: a.globalData.commonShareTitle,
            path: t[0],
            imageUrl: t[1],
            success: function(t) {},
            fail: function(t) {}
        };
    }
});